import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import rootSaga from '../sagas';
import reducers from '../reducers';

const sagaMiddleware = createSagaMiddleware();

// 日志中间件
const logger = store => next => (action) => {
  console.log('%c[DISPATCH]', 'color: #61afef;', action);
  const result = next(action);
  console.log('%c[NEXT_STATE]', 'color: #56b6c2;', store.getState());
  return result;
};

const createStoreWithMiddleware = applyMiddleware(sagaMiddleware, logger)(createStore);

const store = createStoreWithMiddleware(reducers);

sagaMiddleware.run(rootSaga);

window.store = store;


export default store;
